﻿using System; 
using System.Text;
using System.Collections.Generic; 
using System.Data;
using System.Data.SqlClient;
using ART.Data;
using ART.Common;
using ART.Model;
using ART.Cache;

namespace ART.BLL {
  //UserGraduate
 	public partial class B_UserGraduate
	{
   		
		public B_UserGraduate()
		{}
        #region __________基础方法__________
		/// <summary>
		/// 删除指定缓存
		/// </summary>
		public void ClearCache(string key)
		{
		    string CacheKey = "BLL/UserGraduate";
			if(!string.IsNullOrEmpty(key)){
			    CacheKey+="/"+key;
			}
			LRSCache.GetCacheService().RemoveObject(CacheKey);
		}
		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(ART.Model.M_UserGraduate model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into UserGraduate(");			
            strSql.Append("startDate,EndDate,SchoolId,Vocationaltid,VocationalOther,EduBround,Remarks,Sort,CreateTime,UId");
			strSql.Append(") values (");
            strSql.Append("@startDate,@EndDate,@SchoolId,@Vocationaltid,@VocationalOther,@EduBround,@Remarks,@Sort,@CreateTime,@UId");            
            strSql.Append(") ");            
            strSql.Append(";select @@IDENTITY");	
			#region __________参数__________	
			SqlParameter[] parameters = {
			            new SqlParameter("@startDate", SqlDbType.DateTime) ,            
                        new SqlParameter("@EndDate", SqlDbType.DateTime) ,            
                        new SqlParameter("@SchoolId", SqlDbType.Int,4) ,            
                        new SqlParameter("@Vocationaltid", SqlDbType.Int,4) ,            
                        new SqlParameter("@VocationalOther", SqlDbType.VarChar,150) ,            
                        new SqlParameter("@EduBround", SqlDbType.Int,4) ,            
                        new SqlParameter("@Remarks", SqlDbType.VarChar,255) ,            
                        new SqlParameter("@Sort", SqlDbType.Int,4) ,            
                        new SqlParameter("@CreateTime", SqlDbType.DateTime) ,            
                        new SqlParameter("@UId", SqlDbType.Int,4)             
              
            };
			
			            
            parameters[0].Value = model.startDate;                        
            parameters[1].Value = model.EndDate;                        
            parameters[2].Value = model.SchoolId;                        
            parameters[3].Value = model.Vocationaltid;                        
            parameters[4].Value = model.VocationalOther;                        
            parameters[5].Value = model.EduBround;                        
            parameters[6].Value = model.Remarks;                        
            parameters[7].Value = model.Sort;                        
            parameters[8].Value = model.CreateTime;                        
            parameters[9].Value = model.UId;            			
            #endregion
			   
			object obj = SqlHelper.ExecScalar(strSql.ToString(),parameters);			
			if (obj == null)
			{
				return 0;
			}
			else
			{
				                    
            	return Convert.ToInt32(obj);
                                                                  
			}			   
            		
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(ART.Model.M_UserGraduate model)
		{
		    StringBuilder strSql=new StringBuilder();
			#region __________语句__________
			strSql.Append("update UserGraduate set ");
			                                                
            strSql.Append(" startDate = @startDate , ");                                    
            strSql.Append(" EndDate = @EndDate , ");                                    
            strSql.Append(" SchoolId = @SchoolId , ");                                    
            strSql.Append(" Vocationaltid = @Vocationaltid , ");                                    
            strSql.Append(" VocationalOther = @VocationalOther , ");                                    
            strSql.Append(" EduBround = @EduBround , ");                                    
            strSql.Append(" Remarks = @Remarks , ");                                    
            strSql.Append(" Sort = @Sort , ");                                    
            strSql.Append(" CreateTime = @CreateTime , ");                                    
            strSql.Append(" UId = @UId  ");            			
			strSql.Append(" where Id=@Id ");
			
			#endregion	
			
			#region __________参数__________	
            SqlParameter[] parameters = {
			            new SqlParameter("@Id", SqlDbType.Int,4) ,            
                        new SqlParameter("@startDate", SqlDbType.DateTime) ,            
                        new SqlParameter("@EndDate", SqlDbType.DateTime) ,            
                        new SqlParameter("@SchoolId", SqlDbType.Int,4) ,            
                        new SqlParameter("@Vocationaltid", SqlDbType.Int,4) ,            
                        new SqlParameter("@VocationalOther", SqlDbType.VarChar,150) ,            
                        new SqlParameter("@EduBround", SqlDbType.Int,4) ,            
                        new SqlParameter("@Remarks", SqlDbType.VarChar,255) ,            
                        new SqlParameter("@Sort", SqlDbType.Int,4) ,            
                        new SqlParameter("@CreateTime", SqlDbType.DateTime) ,            
                        new SqlParameter("@UId", SqlDbType.Int,4)             
              
            };
            			            
            parameters[0].Value = model.Id;                        
            parameters[1].Value = model.startDate;                        
            parameters[2].Value = model.EndDate;                        
            parameters[3].Value = model.SchoolId;                        
            parameters[4].Value = model.Vocationaltid;                        
            parameters[5].Value = model.VocationalOther;                        
            parameters[6].Value = model.EduBround;                        
            parameters[7].Value = model.Remarks;                        
            parameters[8].Value = model.Sort;                        
            parameters[9].Value = model.CreateTime;                        
            parameters[10].Value = model.UId;            			
            #endregion
			
            int rows=SqlHelper.ExecNonQuery(strSql.ToString(),parameters);
			if (rows > 0)
			{
			//string cachekey="info_"+Id;
			//ClearCache(cachekey);
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int Id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from UserGraduate ");
			strSql.Append(" where Id=@Id");
						SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
			parameters[0].Value = Id;

			int rows=SqlHelper.ExecNonQuery(strSql.ToString(),parameters);
			
			//string cachekey="info_"+Id;
			//ClearCache(cachekey);
			
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
				/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string Idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from UserGraduate ");
			strSql.Append(" where ID in ("+Idlist + ")  ");
			int rows=SqlHelper.ExecNonQuery(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ART.Model.M_UserGraduate GetModel(int Id)
		{
			//string CacheKey = "BLL/UserGraduate/info_" + Id;
			//object objModel = LRSCache.GetCacheService().RetrieveObject(CacheKey);
			// if (objModel == null)
			 //{
				StringBuilder strSql=new StringBuilder();
				strSql.Append("select * from UserGraduate ");
				strSql.Append(" where Id=@Id");
				
							SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
			parameters[0].Value = Id;

				
				ART.Model.M_UserGraduate model=new ART.Model.M_UserGraduate();
				DataSet ds=SqlHelper.ExecDataSet(strSql.ToString(),parameters);
				
				if(ds.Tables[0].Rows.Count>0)
				{
				    #region __________实体赋值__________
													if(ds.Tables[0].Rows[0]["Id"].ToString()!="")
				{
					model.Id=int.Parse(ds.Tables[0].Rows[0]["Id"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["startDate"].ToString()!="")
				{
					model.startDate=DateTime.Parse(ds.Tables[0].Rows[0]["startDate"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["EndDate"].ToString()!="")
				{
					model.EndDate=DateTime.Parse(ds.Tables[0].Rows[0]["EndDate"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["SchoolId"].ToString()!="")
				{
					model.SchoolId=int.Parse(ds.Tables[0].Rows[0]["SchoolId"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["Vocationaltid"].ToString()!="")
				{
					model.Vocationaltid=int.Parse(ds.Tables[0].Rows[0]["Vocationaltid"].ToString());
				}
																																				model.VocationalOther= ds.Tables[0].Rows[0]["VocationalOther"].ToString();
																												if(ds.Tables[0].Rows[0]["EduBround"].ToString()!="")
				{
					model.EduBround=int.Parse(ds.Tables[0].Rows[0]["EduBround"].ToString());
				}
																																				model.Remarks= ds.Tables[0].Rows[0]["Remarks"].ToString();
																												if(ds.Tables[0].Rows[0]["Sort"].ToString()!="")
				{
					model.Sort=int.Parse(ds.Tables[0].Rows[0]["Sort"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["CreateTime"].ToString()!="")
				{
					model.CreateTime=DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["UId"].ToString()!="")
				{
					model.UId=int.Parse(ds.Tables[0].Rows[0]["UId"].ToString());
				}
																									
						
					#endregion
					
					//LRSCache.GetCacheService().AddObject(CacheKey, objModel, 2*60*60);		
					return model;
				}
				else
				{
					return null;
				}
				 
			 //}
			 //return (ART.Model.M_UserGraduate)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return GetList(0,strWhere,"");
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return GetList(0,"*",strWhere,filedOrder);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string FieldName,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" "+FieldName+" FROM UserGraduate ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			if(filedOrder.Trim()!="")
			{
				strSql.Append(" order by " + filedOrder);
			}
			return SqlHelper.ExecDataSet(strSql.ToString());
		}
#endregion

      #region __________自定义方法__________

      #endregion 
	}
}

